package com.leejw.tradeblogsystem.controller;


import com.leejw.tradeblogsystem.common.Result;
import com.leejw.tradeblogsystem.model.User;
import com.leejw.tradeblogsystem.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author: jwli3
 * @Desc: 用户管理
 * @create: 2024-08-10
 **/
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService service;


    @RequestMapping("/query")
    public @ResponseBody User queryUser(Integer id) {
        User user = service.findUserById(id);
        return user;
    }
    @ResponseBody
    @RequestMapping("/index")
    public String index(@RequestBody User user) {
        String name = user.getName();
        String password = user.getPassword();
        User result = service.login(name, password);
        if (result == null) {
            return "USER_NOT_EXIST";
        }
        return "SUCCESS";
    }

}

